#include <stdio.h>
#include <math.h>

//查找数字的个数
int SchNum(int num, int F) {
    int sum = 0;
    int rem = 0;
    int count = 0;
    int nums = num;
    if (num < 10 && F == 0) {
        return 0;
    }
    while (num) {
        rem = num % 10;
        if (F == 0 && rem != 0) {
            int tmp = 1;
            for (int i = 0; i < count - 1; i++) {
                tmp = tmp * 10 + 1;
            }
            sum += rem * pow(10, count - 1) * count - tmp;
        } else if (rem < F) {
            sum += rem * pow(10, count - 1) * count;
        } else if (rem == F) {
            sum += rem * pow(10, count - 1) * count + nums % (int) pow(10, count) + 1;
        } else if (rem > F) {
            sum += pow(10, count) * (count + 1) - (10 - rem) * pow(10, count - 1) * count;
        }

        // 1 - 1 + 1
        // 20 - 11 + 2
        // 300 - 111 + 3
        // 4000 - 1111 + 4

        // 0 + 1
        // 9 + 2
        // 189 + 3
        // 2889 + 4
        // 38889 + 5

        num /= 10;
        count++;
    }

    return sum;
}

int main()
{
    int F = 0;
    int num = 0;
    scanf("%d%d", &num, &F);
    int n = SchNum(num, F);
    printf("%d", n);
    return 0;
}